<template>
	<view class="item-block">
		<view class="header-search">
			<u--input placeholder="请输入赛事名称" suffixIcon="search" @confirm='inputconfirm'
				suffixIconStyle="color: #bfbfbf"></u--input>
		</view>
		<view class="bot-item">
			<!-- 	<view @click="openselect">
				<u--input border="bottom" :placeholder="show?'请选择比赛状态▲':'请选择比赛状态▼'" :disabled='true'
					disabledColor='#f4f4f4'></u--input>
			</view> -->
			<view class="item-list">
				<view class="list_item">
					<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltolower="lower"
						:style="{ height: `calc(100vh - 96px)` }">
						<view class="polular_list_item" v-for="(item,index) in datalist" :key="index" @click="lookcode(item.id)">

							<view class="item_left">
								<view class="title_item">
									{{item.raceName}}
								</view>
								<view class="team_item">
									参赛队伍：{{item.joinNum}}/{{item.teamNum}}
								</view>
								<view class="address_item">
									<span class="iconfont icon-dizhi"></span>
									<span class="address_text">{{item.placeName}}</span>
								</view>
							</view>
							<view class="item_right">
								<view class="right_top">
									<view class="time">
										赛事开始时间
									</view>
									<view class="time">
										{{item.startTime}}
									</view>
								</view>
								<view class="iconfont icon-erweima" >

								</view>
							</view>
						</view>
						<u-loadmore line :status="status" :loading-text="loadingText" :nomore-text="nomoreText"
							v-if="this.pagetotal!=0" />
					</scroll-view>
				</view>
			</view>
		</view>
		<u-modal :show="show" :title="title" :closeOnClickOverlay="true" @close='show=false' :showConfirmButton='false'>
			<!-- <view class="" style="width: 100%; display: flex; justify-content: center;"  v-if="statetype">
				已核销
			</view> -->
			<view class="slot-content item" style="width: 100%; display: flex; justify-content: center; flex-direction: column; align-items: center;" >
				<image style="width: 200px; height: 200px; background-color: #eeeeee;" :src="src"></image>
				<view class="">
					{{checkstate?'已核销':'未核销'}}
				</view>
				<view class="" v-if="checkstate">
					核销时间:{{checkTime}}
				</view>
			</view>
			
			<!-- <u-button slot="confirmButton" text="确定" class="buttwo" type="success" shape="circle"
				@click="show=false"></u-button> -->

		</u-modal>
		<!-- ▼▲ -->
		<!-- <u-picker :show="show" :columns="columns" title="请选择比赛状态" @cancel="cancel" @confirm="confirm"></u-picker> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checkstate:'',
				checkTime:'',
				// statetype:false,
				show: false,
				src: '',
				// show: false,
				// columns: [
				// 	['未结束', '已结束']
				// ],
				datalist: [],
				query: {
					pagNum: 1,
					pageSize: 10,
					raceState: '',
					raceName: '',
				},
				status: 'loading',
				loadingText: '努力加载中',
				nomoreText: '没有更多了',
				statename: '',
				pagetotal: 0,
			}
		},
		created() {

		},
		mounted() {
			this.eventlist()


		},
		onLoad(options) {

		},
		methods: {
			lookcode(e) {
				const that = this
				this.$request(`/race/getCheckState/${e}`, 'get')
					.then(
						res => {
							// if (res.data.data) {
								that.checkstate=res.data.data.checkState
								that.checkTime=res.data.data.checkTime
							// 	that.statetype = true
							// 	that.show = true
							// } else {
								// that.statetype = false
								const header = {
									Authorization: ""
								}
								const userinfo = uni.getStorageSync('userinfokey')
								header.Authorization = userinfo.token
								uni.request({
									url: `https://api.ptgolf.net/app/generate-qrcode?text=${e}`, //挂上你的请求地址
									method: 'GET',
									// arraybuffer
									responseType: 'arraybuffer',
									header: header,
									success: obj => {
										let base64 = 'data:image/png;base64,' + uni.arrayBufferToBase64(obj
											.data)
										that.src = base64
										that.show = true
									},
									fail: (err) => {
										console.log(err);
									}
								});
							// }

						})






			},
			eventlist() {
				const that = this
				this.$request(`/mine/raceList`, 'post', this.query)
					.then(
						res => {
							const array = res.data.data.records
							// array.forEach(item => {
							// 	let currentTime = new Date();
							// 	// 判断 racestate 是否为 1
							// 	if (item.raceState == 1) {
							// 		item.statetype = 1;
							// 		item.urlimg = 'https://web.ptgolf.net/image/webchat/5.png';
							// 	}
							// 	// 如果 racestate 不是 1，判断当前时间是否大于 startime
							// 	else if (currentTime > new Date(item.startTime)) {
							// 		item.statetype = 2;
							// 		item.urlimg = 'https://web.ptgolf.net/image/webchat/6.png';
							// 	}
							// 	// 如果还是不满足，判断 joinNum 是否等于 teamNum
							// 	else if (item.joinNum == item.teamNum) {
							// 		item.statetype = 3;
							// 		item.urlimg = 'https://web.ptgolf.net/image/webchat/18.png';
							// 	}
							// 	// 如果还不满足，判断当前时间是否大于 signstar
							// 	else if (currentTime > new Date(item.signStart)) {
							// 		item.statetype = 4;
							// 		item.urlimg = 'https://web.ptgolf.net/image/webchat/19.png';
							// 	}
							// 	// 如果都不满足，默认设置为 statetype 5 
							// 	else {
							// 		item.statetype = 5;
							// 		item.urlimg = 'https://web.ptgolf.net/image/webchat/20.png';
							// 	}
							// });

							this.datalist = this.datalist.concat(array)
							this.pagetotal = res.data.data.total
							if (this.pagetotal == this.datalist.length) {
								this.status = 'nomore'
							}

						})
			},
			openselect() {
				this.show = true
			},
			lower() {
				this.status = 'loading'
				this.query.pagNum++
				// setTimeout(() => {
					this.eventlist()
				// }, 2000);
			},
			inputconfirm(e) {
				this.query.raceName = e
				this.datalist = []
				this.query.pagNum = 1
				this.eventlist()
			},

		}
	}
</script>

<style scoped lang="scss">
	.item-block {
		background-color: #1e1e1e;
		height: 100vh;

		::v-deep .u-button {
			border-radius: 25px;
			border: 0px;
			background-color: #de3600;
			height: 47px;
		}

		.icon-erweima {
			font-size: 40px;
		}

		::-webkit-scrollbar {
			width: 0px;
			/* 滚动条的宽度 */
		}

		.header-search {
			padding: 10px 20px;

			::v-deep .u-input {
				background-color: #f6f7f9;
				// border: 1px solid #dededf;
				border-radius: 18px;
				box-shadow: 0 0 2px #b9b9ba;

				/* 添加阴影 */
				.u-icon__icon {
					color: #de3600 !important;
					font-size: 25px !important;
					font-weight: 700 !important;

				}
			}
		}

		.bot-item {
			height: calc(100vh - 56px - 20px);
			background-color: #f4f4f4;
			border-radius: 15px 15px 0 0;
			padding: 10px 20px;

			::v-deep .u-input {
				border-bottom: 1px solid #d1d1d1;

			}

			.item-list {
				margin-top: 10px;

				.polular_list_item {
					background-size: 100% auto;
					margin-bottom: 10px;
					height: 95px;
					background-color: #fff;
					border-radius: 10px;
					box-shadow: 0 0 2px #b9b9ba;
					padding: 8px 15px;
					display: flex;
					justify-content: space-between;
					position: relative;

					.but_img {
						position: absolute;
						height: 25px;
						width: 35px;
						background-size: 100% 100%;
						bottom: 13px;
						right: 72px;
						z-index: 9;
					}

					.item_left {
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.title_item {
							font-size: 32rpx;
							font-weight: 600;
						}

						.team_item {
							font-size: 12px;
							color: #afafaf;
						}

						.address_item {
							margin-top: 20px;

							.icon-dizhi {
								font-size: 13px;
								border-radius: 10px;
								padding: 2px;
								background-color: #de3600;
								color: #fff;
								margin-right: 3px;
							}

							.address_text {
								font-size: 12px;
								color: #afafaf;
							}
						}
					}

					.item_right {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						align-items: flex-end;

						.right_top {
							font-size: 10px;
							color: #afafaf;
							display: flex;
							flex-direction: column;
							align-items: flex-end;

						}

						::v-deep .u-button {
							color: #f6f7f9;
							border: 0px;
							border-radius: 30px;
							background-color: #de3600;
							height: 30px;
							width: 75px;
						}
					}
				}

			}
		}
	}
</style>